<template>
    <div class="list" ref="wrapper">
        <div>
        <div class="area">
            <div class="title">当前城市</div>
            <div class="button-list">
                <div class="button-wrapper">
                    <div class="button">渭南</div>
                </div>
            </div>
        </div>
         <div class="area">
            <div class="title">热门城市</div>
            <div class="button-list">
                <div class="button-wrapper" v-for="item of hotcitys" :key="item.id">
                    <div class="button">{{item.name}}</div>
                </div>
            </div>
        </div>
        <!-- citys是一个对象 -->
        <div class="area" v-for="(item,key) of citys" :key="key" :ref="key">
            <div class="title">{{key}}</div>
            <div class="item-list">
                <div class="item" v-for="innerItem of item" :key="innerItem.id">{{innerItem.name}}</div>
            </div>
        </div>
        </div>
    </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'List',
  props: {
    citys: Object,
    hotcitys: Array,
    letter: String
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.wrapper)
  },
  watch: {
    letter () {
      if (this.letter) {
        const element = this.$refs[this.letter][0]
        // console.log(element)
        this.scroll.scrollToElement(element)
      }
    }
  }
}
</script>

<style lang='stylus' scoped>
 @import '~styles/varible.styl';
.list
 overflow :hidden
 position :absolute
 top:1.6rem
 left :0
 right :0
 bottom :0
 .title
  line-height :.4rem
  background :#eee
  padding-left :.2rem
  color :#666
  font-size :.26rem
  font-weight :900
  border-bottom :1px solid #ccc
 .button-list
   padding: .1rem .6rem .1rem .1rem
   overflow : hidden
   .button-wrapper
     float :left
     width : 33.33%
     .button
       margin :.1rem
       max-resolution 0.1rem
       padding :.1rem 0
       text-align :center
       border: .02rem solid #ccc
       line-height :.25rem
       border-radius :.1rem
.item-list
    .item
        line-height :.7rem
        padding-left :.2rem
        border-bottom : .01rem solid #ccc

</style>
